//
//  HospitalHomepageViewController.m
//  WE
//
//  Created by apple on 15/11/19.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "HospitalHomepageViewController.h"
#import "Size.h"
#import "HomepageCollectionViewCell.h"
#import "MindViewController.h"
#import "InfirmaryViewController.h"
#import "LiveCountModel.h"
#import "BackButton.h"
#import "MapViewController.h"
#import <Masonry.h>
@interface HospitalHomepageViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

{
    NSArray *imageArray;
    NSArray *simplenesArray;
    NSArray *partArray;
}

@property (nonatomic, strong)UIScrollView *scroll;
@end

@implementation HospitalHomepageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    BackButton *backButton = [[BackButton alloc] initWithFrame:CGRectMake(0, 10, 20, 24)];
//    [backButton addTarget:self action:@selector(pressBack) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
//    self.navigationItem.leftBarButtonItem = backItem;
    
    // Do any additional setup after loading the view.
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"医院主页";
    self.scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,WindowWidth , WindowHeight)];
    [self.view addSubview:self.scroll];
    
    simplenesArray = @[@"智能导诊",@"预约挂号",@"医院简介",@"科室医生",@"医院导航",@"排队候诊",@"当日预约",@"取报告单",@"查处方单",@"支付结算"];
    partArray = @[@"症状自测找医生",@"提前预约先人一步",@"医院详情及评价",@"简介擅长出诊信息",@"地址位置楼层导航",@"实时查看问诊叫号",@"实时挂号快速就诊",@"及时查看检查报告",@"及时查看处方单",@"手机支付免去排队"];
    
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, WindowHeight/7 * 2)];
    imageV.image = [UIImage imageNamed:@"111.jpg"];
    [self.scroll addSubview:imageV];
    
    UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(0, WindowHeight/7 * 2 / 5 * 3, WindowWidth, WindowHeight/7 * 2 / 5 * 2)];
    blackView.backgroundColor = [UIColor blackColor];
    
    blackView.alpha = 0.5;
    [imageV addSubview:blackView];
    UILabel *hospitalLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, WindowWidth - 100, blackView.frame.size.height/4)];
    hospitalLabel.text = @"浙江省立同德医院";
    hospitalLabel.textColor = [UIColor whiteColor];
    [blackView addSubview:hospitalLabel];
    
    UILabel *level = [[UILabel alloc] initWithFrame:CGRectMake(10, blackView.frame.size.height/4 + 5, WindowWidth - 100, blackView.frame.size.height/4)];
    level.text = @"三级甲等";
    level.font = FONT(12);
    level.textColor = [UIColor whiteColor];
    [blackView addSubview:level];
    
    UILabel *address = [[UILabel alloc] initWithFrame:CGRectMake(10, blackView.frame.size.height/2 + 5, WindowWidth - 100, blackView.frame.size.height/4)];
    address.text = @"地址 : 杭州市古翠路";
    address.font = FONT(12);
    address.textColor = [UIColor whiteColor];
    [blackView addSubview:address];
    
    
    UILabel *number = [[UILabel alloc] initWithFrame:CGRectMake(WindowWidth - 50, blackView.frame.size.height/4 + 5, 50, blackView.frame.size.height/4)];
    number.text = @"1573";
    number.textColor = [UIColor whiteColor];
    number.font = FONT(12);
    [blackView addSubview:number];
    
    UILabel *strLabel = [[UILabel alloc] initWithFrame:CGRectMake(WindowWidth - 50, blackView.frame.size.height/2 + 5, 50, blackView.frame.size.height/4)];
    strLabel.text = @"预约量";
    strLabel.textColor = [UIColor whiteColor];
    strLabel.font = FONT(12);
    [blackView addSubview:strLabel];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"☆" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor blackColor];
    button.alpha = 0.5;
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.titleLabel.font = FONT(17);
    button.layer.cornerRadius = 15;
    button.layer.masksToBounds = YES;
    [button addTarget:self action:@selector(pressCollect) forControlEvents:UIControlEventTouchUpInside];
    [imageV addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageV.mas_top).offset(10);
        make.right.equalTo(imageV.mas_right).offset(-10);
        make.height.offset(30);
    }];
    
    [self setupCollectionView];
                       

}

- (void)pressCollect{
    
}

- (void)pressBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupCollectionView{
    UICollectionViewFlowLayout *flowLayout= [[UICollectionViewFlowLayout alloc] init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;//滚动方向
    flowLayout.minimumLineSpacing = 10.0;//行间距(最小值)
    //    flowLayout.headerReferenceSize = CGSizeMake(320, 100);
    
    flowLayout.minimumInteritemSpacing = 10.0;//item间距(最小值)
    flowLayout.itemSize = CGSizeMake((WindowWidth - 30)/2, 70*Height);//item的大小
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);//设置section的边距
    //    flowLayout.headerReferenceSize = CGSizeMake(320, 20);
    //    flowLayout.footerReferenceSize = CGSizeMake(320, 20);
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,WindowHeight/7 * 2 + 64, WindowWidth, WindowHeight - WindowHeight/7 * 2) collectionViewLayout:flowLayout];
    
    [collectionView registerClass:[HomepageCollectionViewCell class] forCellWithReuseIdentifier:@"HomepageCollectionViewCell"];
    //    [collectionView registerClass:[HeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];
    
    collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    collectionView.dataSource = self;
    collectionView.delegate = self;
    collectionView.backgroundColor = [UIColor colorWithRed:0.8685 green:0.8639 blue:0.8731 alpha:1.0];
    
    //    [collectionView registerClass:[HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerIdentifier];
    //    [collectionView registerClass:[FootView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:footerIdentifier];
    
    [self.view addSubview:collectionView];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return 10;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //[self presentViewController:[[XiangceViewController alloc] init] animated:YES completion:nil];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //    if (indexPath.section == 0) {
    static NSString * cellIdentifier = @"HomepageCollectionViewCell";
    //HomepageCollectionViewCell * cell = [[HomepageCollectionViewCell alloc] init];
    HomepageCollectionViewCell *cell = (HomepageCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    
    [cell sizeToFit];
    if (!cell) {
        NSLog(@"cell无法创建");
    }
    // cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.imageV.image = [UIImage imageNamed:@"111"];
    cell.backgroundColor = [UIColor whiteColor];
    cell.simplenessLabel.text = simplenesArray[indexPath.row];
    cell.particularLabel.text = partArray[indexPath.row];
    //cell.particularLabel.text = [NSString stringWithFormat:@"%ld -- %ld",indexPath.section,indexPath.row];
            return cell;
    
    //    static NSString * cellIdentifier = @"cellhuxing";
    //    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    ////    if (cell==nil) {
    ////        cell = [[UICollectionViewCell alloc] initWithFrame:CGRectMake(0, 64, WindowWidth / 2, 100)];
    ////    }
    //    cell.backgroundColor = DEBUG_CLOLR;
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.row == 0) {
        [self.navigationController pushViewController:[[MindViewController alloc] init] animated:YES];
    } else if (indexPath.row == 1){
        LiveCountModel * handle = [LiveCountModel mainLiveCountModel];
        handle.string = @"2";
        
        [self.navigationController pushViewController:[[InfirmaryViewController alloc] init] animated:YES];
        
        
    }else if (indexPath.row == 2){
        
        
        
    }else if (indexPath.row == 3){
        LiveCountModel * handle = [LiveCountModel mainLiveCountModel];
        handle.string = @"2";
        
        
        [self.navigationController pushViewController:[[InfirmaryViewController alloc] init] animated:YES];
        
    }else if (indexPath.row == 4){
        [self.navigationController pushViewController:[[MapViewController alloc] init] animated:YES];
        
        
    }else if(indexPath.row == 5){
        
    }
    
    
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
